#include<stdio.h>
#include<string.h>
typedef struct
{
    char name[37];
    int score;
}student;

int cmp(student*a,student*b);
void swap(student*a,student*b);
int main()
{
    int n;
    scanf("%d",&n);
 
    student *stu1;
    student *stu2;
    student stu[119];
    for(int i=0;i<n;i++)
    {
        getchar();
        scanf("%s",stu[i].name);
        scanf("%d",&stu[i].score);
        
    }

    for(int i=0;i<n;i++)
     for(int j=i;j<n;j++)
     {
         stu1=&stu[i];
         stu2=&stu[j];
         if(cmp(stu1,stu2)==1)
          swap(stu1,stu2);
     }


     for(int i=0;i<n;i++)
     {
         printf("Name:%s\n",stu[i].name);
         printf("total:%d\n",stu[i].score);
         printf("\n");
     }
}

int cmp(student*a,student*b)
{
    if(a->score<b->score)
    {
        return 1;
    }
    else if(a->score==b->score&&strcmp(a->name,b->name)>0)
    {
        return 1;
        /*for(int i=0;i<21;i++)
        {
            if(b->name[i]<a->name[i])
            {
                return 1;
                break;
            }
            else return 0;
        }*/
    }
    else return 0;
}

void swap(student*a,student*b)
{
    int temp1;
    char temp2;

    temp1=a->score;
    a->score=b->score;
    b->score=temp1;

    for(int i=0;i<21;i++)
    {
       temp2=a->name[i];
       a->name[i]=b->name[i];
       b->name[i]=temp2;
    }
}
